﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for HsbcCarMoreDetailDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class HsbcCarMoreDetailDB
    {
        public HsbcCarMoreDetailDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(HsbcCarMoreDetail hsbccarmoredetail)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarMoreDetailInsertUpdateSingleItemHsbc";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarMoreDetailId", hsbccarmoredetail.CECarMoreDetailId);
            _sPara.Add("@CECarID", hsbccarmoredetail.CECarId);
            _sPara.Add("@ProviderCompanyId", hsbccarmoredetail.ProviderCompanyId);
            _sPara.Add("@Salutation", hsbccarmoredetail.Salutation);
            _sPara.Add("@FamilyName", hsbccarmoredetail.FamilyName);
            _sPara.Add("@GivenName", hsbccarmoredetail.GivenName);
            _sPara.Add("@Race", hsbccarmoredetail.Race);
            _sPara.Add("@PostalCode", hsbccarmoredetail.PostalCode);
            _sPara.Add("@UnitNo", hsbccarmoredetail.UnitNo);
            _sPara.Add("@HomeNo", hsbccarmoredetail.HomeNo);
            _sPara.Add("@Address", hsbccarmoredetail.Address);
            _sPara.Add("@NRICNo", hsbccarmoredetail.NRICNo);
            _sPara.Add("@Nationality", hsbccarmoredetail.Nationality);
            _sPara.Add("@MobileNo", hsbccarmoredetail.MobileNo);
            _sPara.Add("@HomePhoneNo", hsbccarmoredetail.HomePhoneNo);
            _sPara.Add("@OfficePhoneNo", hsbccarmoredetail.OfficePhoneNo);
            _sPara.Add("@FaxNo", hsbccarmoredetail.FaxNo);
            _sPara.Add("@EmpName", hsbccarmoredetail.EmpName);
            //_sPara.Add("@HasInsuranceTransferred", hsbccarmoredetail.HasInsuranceTransferred);
            _sPara.Add("@InsCompanyName", hsbccarmoredetail.InsCompanyName);
           //_sPara.Add("@InsVechicleNo", hsbccarmoredetail.InsVechicleNo);
            _sPara.Add("@NCDReason", hsbccarmoredetail.NCDReason);
            _sPara.Add("@NCDOtherReason", hsbccarmoredetail.NCDOtherReason);
            _sPara.Add("@VechicleNo", hsbccarmoredetail.VechicleNo);
            _sPara.Add("@EngineType", hsbccarmoredetail.EngineType);
            _sPara.Add("@PurchasePrice", hsbccarmoredetail.PurchasePrice);
            _sPara.Add("@EngineNo", hsbccarmoredetail.EngineNo);
            _sPara.Add("@ChassisNo", hsbccarmoredetail.ChassisNo);
            _sPara.Add("@HasVechicleModified", hsbccarmoredetail.HasVechicleModified);
            _sPara.Add("@VechicleModifyReason", hsbccarmoredetail.VechicleModifyReason);
            _sPara.Add("@HasHirePurchase", hsbccarmoredetail.HasHirePurchase);
            _sPara.Add("@HPCompanyName", hsbccarmoredetail.HPCompanyName);
            //_sPara.Add("@PurposeofUse", hsbccarmoredetail.PurposeofUse);
            _sPara.Add("@OtherReason", hsbccarmoredetail.OtherReason);
            _sPara.Add("@PamentType", hsbccarmoredetail.PamentType);          
            _sPara.Add("@QuoteRefNo", hsbccarmoredetail.QuoteRefNo);
            _sPara.Add("@RefCEUserId", hsbccarmoredetail.RefCEUserId);
            _sPara.Add("@ViewedDetailId", hsbccarmoredetail.ViewedDetailId);
            _sPara.Add("@Status", hsbccarmoredetail.Status);
            _sPara.Add("@CarResultId", hsbccarmoredetail.CarResultId);
            _sPara.Add("@Info1", hsbccarmoredetail.Info1);
            _sPara.Add("@Info2", hsbccarmoredetail.Info2);
            _sPara.Add("@Info3", hsbccarmoredetail.Info3);
            _sPara.Add("@Info4", hsbccarmoredetail.Info4);
            _sPara.Add("@Info5", hsbccarmoredetail.Info5);
            _sPara.Add("@Info6", hsbccarmoredetail.Info6);
            _sPara.Add("@Info7", hsbccarmoredetail.Info7);

            _sPara.Add("@YearofObtained", hsbccarmoredetail.YearofObtained);
            _sPara.Add("@HasLicenceRevoked", hsbccarmoredetail.HasLicenceRevoked);
            _sPara.Add("@YearofRevoked", hsbccarmoredetail.YearofRevoked);
            _sPara.Add("@RevokedReason", hsbccarmoredetail.RevokedReason);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 UpdateStatus(HsbcCarMoreDetail hsbccarmoredetail)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCISelectedItemStatusUpdateSingleItemHsbc";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarID", hsbccarmoredetail.CECarId);
            _sPara.Add("@CarResultId", hsbccarmoredetail.CarResultId);
            _sPara.Add("@FilePath", hsbccarmoredetail.Info10);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        public HsbcCarMoreDetail GetCarMoreDetail(Int64 CarId, Int64 CEUserId)
        {
            HsbcCarMoreDetail _Hsbccarmoredetail = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarMoreDetailSelectSingleItemHsbc";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarID", CarId);
            _spara.Add("@RefCEUserId", CEUserId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                _Hsbccarmoredetail = new HsbcCarMoreDetail();
                _Hsbccarmoredetail = FillDataRecord(_dt);
            }
            return _Hsbccarmoredetail;
        }

        private HsbcCarMoreDetail FillDataRecord(DataTable myDataTable)
        {
            HsbcCarMoreDetail myCarMoreDetail = new HsbcCarMoreDetail();
            myCarMoreDetail.CECarMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["CECarMoreDetailId"].ToString());
            myCarMoreDetail.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarID"].ToString());
            myCarMoreDetail.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[0]["ProviderCompanyId"].ToString());
            myCarMoreDetail.FamilyName = myDataTable.Rows[0]["FamilyName"].ToString();
            myCarMoreDetail.GivenName = myDataTable.Rows[0]["GivenName"].ToString();
            myCarMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
            myCarMoreDetail.UnitNo = myDataTable.Rows[0]["UnitNo"].ToString();
            myCarMoreDetail.HomeNo = myDataTable.Rows[0]["HomeNo"].ToString();
            myCarMoreDetail.Address = myDataTable.Rows[0]["Address"].ToString();
            myCarMoreDetail.MobileNo = myDataTable.Rows[0]["MobileNo"].ToString();
            myCarMoreDetail.NRICNo = myDataTable.Rows[0]["NRICNo"].ToString();
            myCarMoreDetail.Nationality = myDataTable.Rows[0]["Nationality"].ToString();
            myCarMoreDetail.VechicleNo = myDataTable.Rows[0]["VechicleNo"].ToString();
            myCarMoreDetail.EngineNo = myDataTable.Rows[0]["EngineNo"].ToString();
            myCarMoreDetail.ChassisNo = myDataTable.Rows[0]["ChassisNo"].ToString();
            myCarMoreDetail.HasHirePurchase = Convert.ToBoolean(myDataTable.Rows[0]["HasHirePurchase"].ToString());
            myCarMoreDetail.HPCompanyName = myDataTable.Rows[0]["HPCompanyName"].ToString();
            myCarMoreDetail.OtherReason = myDataTable.Rows[0]["OtherReason"].ToString();
            //myCarMoreDetail.HasPreInsurer = Convert.ToBoolean(myDataTable.Rows[0]["HasPreInsurer"].ToString());
            //myCarMoreDetail.PreInsurerName = myDataTable.Rows[0]["PreInsurerName"].ToString();
            //myCarMoreDetail.PreInsPolicyNo = myDataTable.Rows[0]["PreInsPolicyNo"].ToString();
            //myCarMoreDetail.PreInsExpiryDate = Convert.ToDateTime(myDataTable.Rows[0]["PreInsExpiryDate"].ToString());
            //myCarMoreDetail.HasDemeritPoints = Convert.ToBoolean(myDataTable.Rows[0]["HasDemeritPoints"].ToString());
            //myCarMoreDetail.HasInsuranceTerminated = Convert.ToBoolean(myDataTable.Rows[0]["HasInsuranceTerminated"].ToString());
            //myCarMoreDetail.InsuranceTerminatedReason = myDataTable.Rows[0]["InsuranceTerminatedReason"].ToString();
            //myCarMoreDetail.HasPhysicalImpairment = Convert.ToBoolean(myDataTable.Rows[0]["HasPhysicalImpairment"].ToString());
           // myCarMoreDetail.PhysicalImpairmentReason = myDataTable.Rows[0]["PhysicalImpairmentReason"].ToString();
            myCarMoreDetail.RowGUID = myDataTable.Rows[0]["RowGUID"].ToString();
            myCarMoreDetail.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myCarMoreDetail.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());

            myCarMoreDetail.YearofObtained = Convert.ToInt32(myDataTable.Rows[0]["YearofObtained"].ToString());
            myCarMoreDetail.HasLicenceRevoked = Convert.ToBoolean(myDataTable.Rows[0]["HasLicenceRevoked"].ToString());
            myCarMoreDetail.YearofRevoked = Convert.ToInt32(myDataTable.Rows[0]["YearofRevoked"].ToString());
            myCarMoreDetail.RevokedReason = myDataTable.Rows[0]["RevokedReason"].ToString();

            return myCarMoreDetail;
        }

        public DataSet GetCarPolicyDetails(Int64 CarId, Int64 CEId, Int64 CXCoverTypeId, Int64 ProviderCompanyId)
        {
            DataSet _result = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarInsuranceSelectedPlanSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarId", CarId);
            _spara.Add("@RefCEUserId", CEId);
            _spara.Add("@CITempResultId", CXCoverTypeId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);


            using (DataSet _ds = _db.GetDataSet(_spName, _spara))
            {
                if (_ds != null && _ds.Tables[0].Rows.Count > 0)
                {
                    _result = _ds;
                }
            }
            return _result;
        }

        public string GetProposalPDF(Int64 CarId, string ResultType)
        {
            string _HsbcProposalPDF = "";
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProposalPDFfileSelectSingleItemHsbc";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarID", CarId);
            _spara.Add("@ResultType", ResultType);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                _HsbcProposalPDF = _dt.Rows[0]["FilePath"].ToString();
            }
            return _HsbcProposalPDF;
        }
    }
}